#!/usr/bin/env python

import sys

from optparse import OptionParser

import mp3same

def main():
    if len(sys.argv) == 1:
        sys.stderr.write("Please supply a command--valid commands are:\n")
        cmds = mp3same.cmd_redirect.keys()
        cmds.sort()
        for cmd in cmds:
            sys.stderr.write("\t`" + cmd +"'\n")
        sys.stderr.write("See `mp3same [cmd] -h' for more.\n")
        sys.stderr.flush()
        return 1
        
    if len(sys.argv) == 2 and sys.argv[1] not in mp3same.cmd_redirect:
        sys.stderr.write("Unknown command `" + sys.argv[1] + "'\n")
        sys.stderr.write("Valid commands are: \n")
        cmds = mp3same.cmd_redirect.keys()
        cmds.sort()
        for cmd in cmds:
            sys.stderr.write("\t`" + cmd +"'\n")
        sys.stderr.write("See `mp3same [cmd] -h' for more.\n")
        sys.stderr.flush()
        return 2

    return mp3same.cmd_redirect[sys.argv[1]]()

if __name__ == "__main__":
    sys.exit(main())
